<?php

class AdminController extends Zend_Controller_Action
{
    protected $db;
    
    public function init()
    {
        /* Initialize action controller here */
        /*if (!Zend_Auth::getInstance()->hasIdentity() || !isset(Zend_Auth::getInstance()->getIdentity()->username)) {
            $param = array(
            'action' => 'admin',
            'controller' => 'index',
            'msg' => 'Session Timeout silahkan login kembali !'
            );
            $this->_redirect($this->view->url($param, 'default', true));
        }
         * 
         */

        $session = new Zend_Session_Namespace('Zend_Auth_Admin');
        $this->sess = $session->data;

        $this->_helper->layout->setLayout('admin');

        if(!isset($this->sess)){
            $param = array(
            'action' => 'admin',
            'controller' => 'index',
            'msg' => 'Session Timeout silahkan login kembali !'
            );
            $this->_redirect($this->view->url($param, 'default', true));
        }

        $this->admin = new Application_Model_Admin();
        
        $this->request = $this->getRequest();
        $this->param = $this->request->getParams();

        $session->action = $this->param['action'];

    }

    public function indexAction()
    {

        //

    }
    


    public function appwithdrawAction()
    {

        ///
    }


    public function followupwithdrawAction()
    {

        if ($this->getRequest()->isPost()) {
            $formData  = $this->_request->getPost();
            
            $flag = $formData['flag'];
            
            $id   = $formData['trans_hid'];
            $ket = $formData['ket'];

            $err = 0;
            $this->view->errorMsg = "";

            /*
             * Check Captcha Input
            
            $captcha = new Application_Model_CaptchaValidator();
            if (!$captcha->validateCaptcha($formData['captcha'])){
                $this->view->errorMsg .= "* Kode keamanan salah.<br>";
                //return;
                $err = 1;
            }
             * 
             */


            $msg = "";
            if ($err == 0){
                    unset($formData['register']);

                    //$auth = Zend_Auth::getInstance();
                    //$identity = $auth->getIdentity();

                    // Insert Transfer
                    if ($flag == 1){ //Approve                   
                        $dataT = $this->admin->prosesWithdraw($id, $ket);
                    }else if ($flag == -1){ //Cancel
                        $dataT = $this->admin->cancelWithdraw($id, $ket);
                    }else{ //Pending
                        $dataT = $this->admin->pendingWithdraw($id, $ket);
                        //$dataT = array("code" => 0, "msg" => "Penarikan dipending");
                    }
                        
                    $msg = $dataT["msg"];
                    $code = $dataT["code"];

                    $this->view->code = $code;

                    if($code == 0){
                        $param = array(
                        'action' => 'followupwithdraw',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;
                    }

            }else{

                //$form = new Application_Form_Accounts_Transfer();
                //$sess = new Zend_Session_Namespace();

                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $this->param;
            }


            //$this->view->id = $msg;

        }else{

            if (isset($this->param['code']) && $this->param['code'] == 0){
                $this->view->id = $this->param['msg'];
                $this->view->code = $this->param['code'];
            }else{
                $id = $this->param['id'];

                $data = $this->admin->detailWithdraw($id);


                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $data;
            }
        }
    }


    function addroAction(){

        // Jika Submit Search
        if (isset($this->param['member_code'])){
                $this->view->data = $this->param;
        }else{

            if ($this->getRequest()->isPost()) {
                $formData  = $this->_request->getPost();

                $roList   = $formData['roList'];
                $flag   = $formData['flag'];

                $err = 0;
                $this->view->errorMsg = "";

                /*
                 * Check List
                 */
                if ($roList == ""){
                    $this->view->errorMsg .= "* Member harus dipilih.<br>";
                    //return;
                    $err = 1;
                }


                $msg = "";
                if ($err == 0){

                        // Insert Transfer
                        $dataT = $this->admin->setRO($roList, $flag);
                        $msg = $dataT["msg"];
                        $code = $dataT['code'];

                        $this->view->code = $code;

                        if($code == 0){
                            $param = array(
                            'action' => 'addro',
                            'controller' => 'admin',
                            'code' => $code,
                            'msg' => $msg
                            );

                            $this->_redirect($this->view->url($param, 'default', true));
                        }else{
                            $this->view->errorMsg = $msg;
                            $this->view->data = $this->param;
                        }

                }else{

                    //$form = new Application_Form_Accounts_Transfer();
                    //$sess = new Zend_Session_Namespace();

                    //$form->populate($this->param);

                    //$this->view->form = $form;

                    $this->view->code = 1;
                    $this->view->data = $this->param;
                }


                //$this->view->id = $msg;

            }else{

                if (isset($this->param['code']) && $this->param['code'] == 0){
                    $this->view->id = $this->param['msg'];
                    $this->view->code = $this->param['code'];
                }else{
                    //$id = $this->param['id'];

                    //$data = $this->admin->detailWithdraw($id);


                    //$form->populate($this->param);

                    //$this->view->form = $form;

                    $this->view->code = 1;
                    //$this->view->data = $data;
                }
            }
        }
    }



    public function apptopupAction()
    {

        ///
    }


    public function followuptopupAction()
    {

        if ($this->getRequest()->isPost()) {
            $formData  = $this->_request->getPost();

            $id   = $formData['trans_hid'];
            $acc_num = $formData['acc_num1'];
            $jenisTopup = $formData['attr3'];
            $topup = $formData['amt2'];

            $err = 0;
            $this->view->errorMsg = "";

            /*
             * Check Captcha Input
             */
            $captcha = new Application_Model_CaptchaValidator();
            if (!$captcha->validateCaptcha($formData['captcha'])){
                $this->view->errorMsg .= "* Kode keamanan salah.<br>";
                //return;
                $err = 1;
            }


            $msg = "";
            if ($err == 0){
                    unset($formData['register']);

                    //$auth = Zend_Auth::getInstance();
                    //$identity = $auth->getIdentity();

                    // Insert Transfer
                    $dataT = $this->admin->prosesTopup($id,$acc_num,$topup,$jenisTopup);
                    $msg = $dataT["msg"];
                    $code = $dataT['code'];

                    $this->view->code = $code;

                    if($code == 0){
                        $param = array(
                        'action' => 'followuptopup',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;
                    }

            }else{

                //$form = new Application_Form_Accounts_Transfer();
                //$sess = new Zend_Session_Namespace();

                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $this->param;
            }


            //$this->view->id = $msg;

        }else{

            if (isset($this->param['code']) && $this->param['code'] == 0){
                $this->view->id = $this->param['msg'];
                $this->view->code = $this->param['code'];
            }else{
                $id = $this->param['id'];

                $data = $this->admin->detailTopup($id);


                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $data;
            }
        }
    }


   function changepassAction(){

        if ($this->getRequest()->isPost()) {
            $formData  = $this->_request->getPost();

            $passLama   = $formData['pass_lama'];
            $passBaru   = $formData['pass_baru'];
            $passBaru2   = $formData['pass_baru2'];

            $err = 0;
            $this->view->errorMsg = "";


            /*
             * Cek PIN Baru
             */

            if ($passBaru != $passBaru2){
                $this->view->errorMsg .= "* Password Baru dan Konfirmasi Password Baru tidak sama.<br>";
                //return;
                $err = 1;
            }


            // Cek Pass Lama
            //$auth = Zend_Auth::getInstance();
            //$identity = $auth->getIdentity();
            $username = $this->sess->username;

            if ($this->sess->pass != $passLama){
                $this->view->errorMsg .= "* Password Lama tidak sesuai.<br>";
                $err = 1;
            }

            $msg = "";
            if ($err == 0){
                    // Ganti Password
                    $dataP = $this->admin->gantiPass($username, $passBaru);
                    $msg = $dataP["msg"];
                    $code = $dataP['code'];

                    $this->view->code = $code;

                    if($code == 0){
                        $param = array(
                        'action' => 'changepass',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;
                    }

            }else{

                //$form = new Application_Form_Accounts_Transfer();
                //$sess = new Zend_Session_Namespace();

                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $this->param;
            }


            //$this->view->id = $msg;

        }else{

            if (isset($this->param['code']) && $this->param['code'] == 0){
                $this->view->id = $this->param['msg'];
                $this->view->code = $this->param['code'];
            }else{
                //$form = new Application_Form_Accounts_Transfer();
                //$sess = new Zend_Session_Namespace();


                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $this->param;
            }
        }
    }

    function smsoutboxAction(){

        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');

        $notel = (isset($this->param['notel'])) ? $this->param['notel'] : "";

        $arrDate = array('notel' => $notel, 'date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;

        // Jika Submit Search
        //if (isset($this->param['notel']) || isset($this->param['date1'])){
                //$this->view->data = $this->param;
        //}
    }


    public function sendsmsAction()
    {

        if ($this->getRequest()->isPost()) {
            $formData  = $this->_request->getPost();

            $tlp  = str_replace(";",",",$formData['tlp']);
            $pesan = $formData['pesan'];

            $err = 0;
            $this->view->errorMsg = "";

            $msg = "";
            if ($err == 0){

                    $arrTlp = explode(",", $tlp);

                    for ($x=0; $x<count($arrTlp); $x++){
                        
                        $tlp = trim($arrTlp[$x]);

                        if ($tlp != ""){
                            // Insert Outbox
                            $dataT = $this->admin->sendSMS($tlp, $pesan);
                            $msg = $dataT["msg"];
                            $code = $dataT['code'];
                        }
                    }

                    $this->view->code = $code;

                    if($code == 0){
                        $param = array(
                        'action' => 'sendsms',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;
                    }

            }else{



                $this->view->code = 1;
                $this->view->data = $this->param;
            }



        }else{

            if (isset($this->param['code']) && $this->param['code'] == 0){
                $this->view->id = $this->param['msg'];
                $this->view->code = $this->param['code'];
            }else{
                //$id = $this->param['id'];

                //$data = $this->admin->getDetailSMSWording($id);



                $this->view->code = 1;
                //$this->view->data = $data;
            }
        }
    }


    public function smswordingAction()
    {

        ///
    }


    public function editwordingAction()
    {

        if ($this->getRequest()->isPost()) {
            $formData  = $this->_request->getPost();

            $id   = $formData['id'];
            $wording = $formData['wording'];

            $err = 0;
            $this->view->errorMsg = "";

            $msg = "";
            if ($err == 0){
                    unset($formData['register']);

                    //$auth = Zend_Auth::getInstance();
                    //$identity = $auth->getIdentity();

                    // Insert Transfer
                    $dataT = $this->admin->editSMSWording($id,$wording);
                    $msg = $dataT["msg"];
                    $code = $dataT['code'];

                    $this->view->code = $code;

                    if($code == 0){
                        $param = array(
                        'action' => 'editwording',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;
                    }

            }else{

               

                $this->view->code = 1;
                $this->view->data = $this->param;
            }



        }else{

            if (isset($this->param['code']) && $this->param['code'] == 0){
                $this->view->id = $this->param['msg'];
                $this->view->code = $this->param['code'];
            }else{
                $id = $this->param['id'];

                $data = $this->admin->getDetailSMSWording($id);



                $this->view->code = 1;
                $this->view->data = $data;
            }
        }
    }



    public function weeklybalanceAction()
    {
        
        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');

        $arrDate = array('date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;
    }


    public function keuanganAction()
    {

        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")-11 , date("d"), date("Y")));
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")-11  , date("d"), date("Y")));
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');

        $arrDate = array('date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;
    }


    public function editmemberAction()
    {

        if ($this->getRequest()->isPost()) {

            $formData  = $this->_request->getPost();

            $memberId   = $formData['member_id'];
            $memberCode = $formData['member_code'];
            $memberName = $formData['member_name'];
            $pin        = "";
            $sponsorId  = $formData['sponsor_id'];
            $parentId   = $formData['parent_id'];
            $registrationDtm  = "";
            $startMemberId    = "";
            $levelId          = "";
            $memberSeq        = "";
            $parentTreenaryId = "";
            $isRepeatOrder    = "";
            $binPos           = "";
            $email      = $formData['email'];

            $addrSeqId  = $formData['addr_seq_id'];
            $addr       = $formData['addr'];
            $blockNo    = $formData['block_no'];
            $kelurahan  = $formData['kelurahan'];
            $kecamatan  = $formData['kecamatan'];
            $city       = $formData['city'];
            $zipCode    = $formData['zip_code'];
            $country    = $formData['country'];
            $startDat   = "";
            $endDat     = "";

            $contactSeqId   = $formData['contact_seq_id'];
            $mobileNo   = $formData['mobile_no'];
            $phoneNo    = $formData['phone_no'];
            $faxNo      = $formData['fax_no'];

            $accId      = $formData['acc_id'];
            $accNum      = $formData['bank_acc_num'];
            $accName     = $memberName;
            $accLiveDtm  = "";
            $accStatus   = "";
            $balance     = 0;
            $idReff1     = $memberId;
            $balanceRorder = 0;

            $accBankId = $formData['acc_bank_id'];
            $bankAccNum = $formData['bank_acc_num'];
            $bankName   = $formData['bank_name'];
            $branchName = $formData['branch_name'];
            $cityName   = $formData['city_name'];

            $err = 0;
            $this->view->errorMsg = "";

            /*
             * Cek Email
             */
            if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                $this->view->errorMsg .= "* Email tidak valid.<br>";
                //return;
                $err = 1;
            }


            /*
             * Check Password same with Confirm Password
             */
            /*
            if ($formData['pin'] == "" || $formData['pin'] != $formData['pin2']) {
                $this->view->errorMsg .= "* Password dan Konfirmasi Password tidak boleh kosong dan harus sama.<br>";
                //return;
                $err = 1;
            }
             *
             */

            /*
             * Check Captcha Input
             */
            $captcha = new Application_Model_CaptchaValidator();
            if (!$captcha->validateCaptcha($formData['captcha'])){
                $this->view->errorMsg .= "* Kode keamanan salah.<br>";
                //return;
                $err = 1;
            }


            $msg = "";
            if ($err == 0){
                    unset($formData['register']);

                    /*
                     * Edit member
                     */
                    $data = $this->admin->editMember($memberId, $memberCode, $memberName, $pin, $sponsorId,
                        $parentId, $registrationDtm, $startMemberId, $levelId, $memberSeq,
                        $parentTreenaryId, $isRepeatOrder, $binPos,
                            $addrSeqId, $addr, $blockNo, $kelurahan, $kecamatan, $city, $zipCode, $country,
                            $contactSeqId, $mobileNo, $phoneNo, $faxNo, $email,
                            $accId, $accNum, $accName, $accLiveDtm, $accStatus,
                            $accBankId, $bankAccNum, $bankName, $memberName, $branchName, $cityName
                        );

                    $memberId   = $data['memberId'];
                    $msg        = $data['msg'];
                    $code       = $data['code'];

                    $this->view->code = $code;

                    //Sukses
                    if($code == 0){
                        $param = array(
                        'action' => 'editmember',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{

                        //$form = new Application_Form_Member_Add();
                        //$sess = new Zend_Session_Namespace();

                        //$form->populate($this->param);

                        //$this->view->form = $form;
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;

                    }


            }else{

                //$form = new Application_Form_Member_Edit();
                //$sess = new Zend_Session_Namespace();

                //$form->populate($this->param);

                //$this->view->form = $form;
                $this->view->data = $this->param;
                $this->view->code = 1;

                $countryList = new Application_Model_Functions();
                $this->view->countryList = $countryList->countryList();

            }


            //$this->view->id = $msg;

        }else{

            $countryList = new Application_Model_Functions();
            $this->view->countryList = $countryList->countryList();

            if (isset($this->param['member_id'])){

                if (isset($this->param['code']) && $this->param['code'] == 0){
                    $this->view->id = $this->param['msg'];
                    $this->view->code = $this->param['code'];
                }else{
                    //$form = new Application_Form_Member_Edit();
                    //$sess = new Zend_Session_Namespace();
                    //$auth = Zend_Auth::getInstance();
                    //$identity = $auth->getIdentity();

                    $arraySession = array('sponsor_id' => $this->sess->member_id,
                                            'sponsor_code' => $this->sess->member_code);

                    $arrayMerge = array_merge($arraySession, $this->param);

                    /*
                     * GET Data Member
                     */

                    $memberId = (isset($this->param['member_id'])) ? $this->param['member_id'] : $this->sess->member_id;

                    $this->member = new Application_Model_Member();
                    $dataMember = $this->member->getMemberDetail($memberId);



                    //$form->populate($dataMember);

                    //$this->view->form = $form;

                    $this->view->data = $dataMember;

                    $this->view->code = 1;
                }
            }else{
                if (isset($this->param['code']) && $this->param['code'] == 0){
                    $this->view->id = $this->param['msg'];
                    $this->view->code = $this->param['code'];
                }else{
                    $this->view->code = 1;
                }
            }
        }
    }
    
    
    public function editpassmemberAction()
    {

        if ($this->getRequest()->isPost()) {

            $formData  = $this->_request->getPost();

            $memberId   = $formData['member_id'];
            $memberCode = $formData['member_code'];
            $pin        = $formData['pin'];
            $pin2        = $formData['pin2'];
            

            $err = 0;
            $this->view->errorMsg = "";

            

            /*
             * Check Password same with Confirm Password
             */
            
            if ($formData['pin'] == "" || $formData['pin'] != $formData['pin2']) {
                $this->view->errorMsg .= "* Password dan Konfirmasi Password tidak boleh kosong dan harus sama.<br>";
                //return;
                $err = 1;
            }
             



            $msg = "";
            if ($err == 0){
                    unset($formData['register']);

                    /*
                     * Edit member
                     */
                    $data = $this->admin->editPassMember($memberId, $pin);

                    $memberId   = $data['memberId'];
                    $msg        = $data['msg'];
                    $code       = $data['code'];

                    $this->view->code = $code;

                    //Sukses
                    if($code == 0){
                        $param = array(
                        'action' => 'editpassmember',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{

                        //$form = new Application_Form_Member_Add();
                        //$sess = new Zend_Session_Namespace();

                        //$form->populate($this->param);

                        //$this->view->form = $form;
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;

                    }


            }else{

                //$form = new Application_Form_Member_Edit();
                //$sess = new Zend_Session_Namespace();

                //$form->populate($this->param);

                //$this->view->form = $form;
                $this->view->data = $this->param;
                $this->view->code = 1;


            }


            //$this->view->id = $msg;

        }else{


            if (isset($this->param['member_id'])){

                if (isset($this->param['code']) && $this->param['code'] == 0){
                    $this->view->id = $this->param['msg'];
                    $this->view->code = $this->param['code'];
                }else{
                    //$form = new Application_Form_Member_Edit();
                    //$sess = new Zend_Session_Namespace();
                    //$auth = Zend_Auth::getInstance();
                    //$identity = $auth->getIdentity();

                    $arraySession = array('sponsor_id' => $this->sess->member_id,
                                            'sponsor_code' => $this->sess->member_code);

                    $arrayMerge = array_merge($arraySession, $this->param);

                    /*
                     * GET Data Member
                     */

                    $memberId = (isset($this->param['member_id'])) ? $this->param['member_id'] : $this->sess->member_id;

                    $this->member = new Application_Model_Member();
                    $dataMember = $this->member->getMemberDetail($memberId);



                    //$form->populate($dataMember);

                    //$this->view->form = $form;

                    $this->view->data = $dataMember;

                    $this->view->code = 1;
                }
            }else{
                if (isset($this->param['code']) && $this->param['code'] == 0){
                    $this->view->id = $this->param['msg'];
                    $this->view->code = $this->param['code'];
                }else{
                    $this->view->code = 1;
                }
            }
        }
    }
    
    
    public function withdrawreportAction()
    {
        
        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');

        $arrDate = array('date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;
    }
    
    public function rewardreportAction()
    {
        
        //$dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d"), date("Y")));
        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d');
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        //$date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd');
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');

        $arrDate = array('date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;
        
        $this->view->rewardList = $this->admin->rewardList();
                
    }
    
    
    function roAction(){

        // Jika Submit Search
        if (isset($this->param['member_code'])){
                $this->view->data = $this->param;
        }else{

            if ($this->getRequest()->isPost()) {
                $formData  = $this->_request->getPost();

                $roList   = $formData['roList'];
                $flag   = $formData['flag'];

                $err = 0;
                $this->view->errorMsg = "";

                /*
                 * Check List
                 */
                if ($roList == ""){
                    $this->view->errorMsg .= "* Member harus dipilih.<br>";
                    //return;
                    $err = 1;
                }


                $msg = "";
                if ($err == 0){

                        // Insert Transfer
                        $dataT = $this->admin->setRO($roList, $flag);
                        $msg = $dataT["msg"];
                        $code = $dataT['code'];

                        $this->view->code = $code;

                        if($code == 0){
                            $param = array(
                            'action' => 'addro',
                            'controller' => 'admin',
                            'code' => $code,
                            'msg' => $msg
                            );

                            $this->_redirect($this->view->url($param, 'default', true));
                        }else{
                            $this->view->errorMsg = $msg;
                            $this->view->data = $this->param;
                        }

                }else{

                    //$form = new Application_Form_Accounts_Transfer();
                    //$sess = new Zend_Session_Namespace();

                    //$form->populate($this->param);

                    //$this->view->form = $form;

                    $this->view->code = 1;
                    $this->view->data = $this->param;
                }


                //$this->view->id = $msg;

            }else{

                if (isset($this->param['code']) && $this->param['code'] == 0){
                    $this->view->id = $this->param['msg'];
                    $this->view->code = $this->param['code'];
                }else{
                    //$id = $this->param['id'];

                    //$data = $this->admin->detailWithdraw($id);


                    //$form->populate($this->param);

                    //$this->view->form = $form;

                    $this->view->code = 1;
                    //$this->view->data = $data;
                }
            }
        }
    }


    public function pertumbuhanbonusAction()
    {

        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');

        $arrDate = array('date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;


    }

    public function gensnAction()
    {

        //

    }

    public function cetaksnAction()
    {

        //


    }

    public function aktifasisnAction()
    {

        if ($this->getRequest()->isPost()) {
            $formData  = $this->_request->getPost();


            $sn   = $formData['sn'];
            $snList   = $formData['snList'];
            $flag   = $formData['flag'];
            
            $err = 0;
            $this->view->errorMsg = "";

            /*
             * Check List
             */
            if ($snList == "" && $flag == 1){
                $this->view->errorMsg .= "* SN harus dipilih.<br>";
                //return;
                $err = 1;
            }


            $msg = "";
            if ($err == 0){

                    $snm = new Application_Model_SerialNumber();
                    $dataT = $snm->aktivasiSN($snList, $flag, $sn);
                    $msg = $dataT["msg"];
                    $code = $dataT['code'];

                    $this->view->code = $code;

                    if($code == 0){
                        $param = array(
                        'action' => 'aktifasisn',
                        'controller' => 'admin',
                        'code' => $code,
                        'msg' => $msg
                        );

                        $this->_redirect($this->view->url($param, 'default', true));
                    }else{
                        $this->view->errorMsg = $msg;
                        $this->view->data = $this->param;
                    }

            }else{

                //$form = new Application_Form_Accounts_Transfer();
                //$sess = new Zend_Session_Namespace();

                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                $this->view->data = $this->param;
            }


            //$this->view->id = $msg;

        }else{

            if (isset($this->param['code']) && $this->param['code'] == 0){
                $this->view->id = $this->param['msg'];
                $this->view->code = $this->param['code'];
            }else{
                //$id = $this->param['id'];

                //$data = $this->admin->detailWithdraw($id);


                //$form->populate($this->param);

                //$this->view->form = $form;

                $this->view->code = 1;
                //$this->view->data = $data;
            }
        } 
    }


    public function memberpasifAction()
    {

        //


    }

    public function memberpasifdetAction()
    {


        if ($this->getRequest()->isPost()) {

            $formData  = $this->_request->getPost();
            $memberId = $formData["member_id"];

            $aktifMember = $this->admin->aktifasiMemberPasif($memberId);

            $msg = $aktifMember["msg"];
            $code = $aktifMember["code"];

            $this->view->code = $code;

            if($code == 0){
                $param = array(
                'action' => 'memberpasifdet',
                'controller' => 'admin',
                'code' => $code,
                'msg' => 'Aktifasi member berhasil'
                );

                $this->_redirect($this->view->url($param, 'default', true));
            }else{
                $this->view->msg = $msg;
                

                $member = new Application_Model_Member();
                $dataMember = $member->getMemberPasifDetail($memberId);

                $funct = new Application_Model_Functions();
                $this->view->country = $funct->getCountry($dataMember['country']);

                $this->view->id = $dataMember;
            }
        }else{

            if (isset($this->param['id'])){
                $memberId   = $this->param['id'];

                $member = new Application_Model_Member();
                $dataMember = $member->getMemberPasifDetail($memberId);

                $funct = new Application_Model_Functions();
                $this->view->country = $funct->getCountry($dataMember['country']);

                $this->view->code = 1;
                $this->view->id = $dataMember;
            }else{
                $this->view->code = $this->param['code'];
                $this->view->msg = $this->param['msg'];
            }
        }
    }


    public function roreportAction()
    {

        $dateTmp1 = (isset($this->param['date1'])) ? $this->param['date1'] : date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $dateTmp2 = (isset($this->param['date2'])) ? $this->param['date2'] : date('Y-m-d');

        $date1 = (isset($this->param['date1'])) ? str_replace('-', '', $this->param['date1']) : date('Ymd', mktime(0, 0, 0, date("m")  , date("d")-7, date("Y")));
        $date2 = (isset($this->param['date2'])) ? str_replace('-', '', $this->param['date2']) : date('Ymd');
        
        $arrDate = array('date1' => $date1, 'date2' => $date2, 'dateTmp1' => $dateTmp1, 'dateTmp2' => $dateTmp2);

        $this->view->data = $arrDate;
        $this->view->code = (isset($this->param['code'])) ? $this->param['code'] : "";
        $this->view->msg = (isset($this->param['msg'])) ? $this->param['msg'] : "";



        if ($this->getRequest()->isPost()) {

            $formData  = $this->_request->getPost();
            $roList = $formData["roList"];
            $flag = $formData["flag"];

            $aktifMember = $this->admin->setStatusRO($roList, $flag);

            $msg = $aktifMember["msg"];
            $code = $aktifMember["code"];

            $this->view->code = $code;

            if($code == 0){
                $param = array(
                'action' => 'roreport',
                'controller' => 'admin',
                'code' => $code,
                'msg' => $msg
                );

                $this->_redirect($this->view->url($param, 'default', true));
            }else{
                $this->view->msg = $msg;


                $member = new Application_Model_Member();
                $dataMember = $member->getMemberPasifDetail($memberId);

                $funct = new Application_Model_Functions();
                $this->view->country = $funct->getCountry($dataMember['country']);

                $this->view->id = $dataMember;
            }
        }

   }

}

